<template>
  <div class="dashboard-container">
    <div class="app-container">
      <!-- 使用组件，接收文件解析结果 -->
      <UploadExcel :on-success="onSuccess"></UploadExcel>
    </div>
  </div>
</template>

<script>
import { importEmployee } from '@/api/employees'

export default {
  name: 'ImportIndex',
  methods: {
    async onSuccess({ results }) {
      const userRelations = {
        '入职日期': 'timeOfEntry',
        '手机号': 'mobile',
        '姓名': 'username',
        '转正日期': 'correctionTime',
        '工号': 'workNumber'
      }
      const data = results.map(t => {
        const item = {}
        for (var key in t) {
          const newKey = userRelations[key]
          // console.log(key, newKey, t[key])
          item[newKey] = t[key]
        }
        return item
      })
      // 发请求
      await importEmployee(data)
      this.$message.success('数据导入成功')
    }
  }
}
</script>

<style scoped lang="scss">

</style>
